package pers.lance.webdemo1.servlet;

import pers.lance.webdemo1.bean.Book;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getSession();
        List books = new ArrayList();
        for(int i = 0; i < 10; i++){
            Book bk = new Book(i, "book" + i);
            books.add(bk);
        }
        Book book = new Book(1, "john");
        req.setAttribute("book", book);
        req.setAttribute("books", books);
        req.getRequestDispatcher("showBooks.jsp").forward(req,resp);
    }
}
